{% extends 'base.html' %}

{% block center_body %}

	<div class="main_con clearfix">
		<div class="left_menu_con clearfix">
			<h3>用户中心</h3>
			<ul>
				<li><a href="{% url "user:info" %}">· 个人信息</a></li>
				<li><a href="{% url "user:order" 1 %}" class="active">· 全部订单</a></li>
				<li><a href="{% url "user:site" %}">· 收货地址</a></li>
			</ul>
		</div>
		<div class="right_content clearfix">
				{% csrf_token %}

				<h3 class="common_title2">全部订单</h3>

                {% for orderinfo in page %}
				<ul class="order_list_th w978 clearfix">
					<li class="col01">{{ orderinfo.create_time|date:'Y-m-d H:i:s' }}</li>
					<li class="col02">订单号：{{ orderinfo.order_id }}</li>
					<li class="col02 stress">{{ orderinfo.order_status_name }}</li>
				</ul>

				<table class="order_list_table w980">
					<tbody>
						<tr>
							<td width="55%">
                                {% for order in orderinfo.order_skus %}
								<ul class="order_goods_list clearfix">
									<li class="col01"><img src="/static/{{ order.sku.image }}"></li>
                                    <li class="col02">{{ order.sku.name }}<em class="good_price">{{ order.sku.price }}</em>元/<em>{{ order.sku.unit }}</em></li>
									<li class="col03">{{ order.count }}件</li>
									<li class="col04">{{ order.amount }}</li>
								</ul>
                                {% endfor %}
							</td>
							<td width="15%">{{ orderinfo.total_price|add:orderinfo.trans_price }}(含运费)元</td>
							<td width="15%">{{ orderinfo.order_status_name }}</td>
							{% if orderinfo.order_status == 0 %}
							<td width="15%"><a href="#"  order_id="{{ orderinfo.order_id }}" status="{{ orderinfo.order_status }}" class="oper_btn">去付款</a></td>
							{% elif orderinfo.order_status == 1 %}
							<td width="15%"><a href="#"  order_id="{{ orderinfo.order_id }}" status="{{ orderinfo.order_status }}" class="oper_btn">提醒发货</a></td>
							{% elif orderinfo.order_status == 2 %}
							<td width="15%"><a href="#" order_id="{{ orderinfo.order_id }}" status="{{ orderinfo.order_status }}" class="oper_btn">查看物流</a></td>
							{% elif orderinfo.order_status == 3 %}
							<td width="15%"><a href="#" order_id="{{ orderinfo.order_id }}" status="{{ orderinfo.order_status }}" class="oper_btn">去评价</a></td>
							{% elif orderinfo.order_status == 4 %}
							<td width="15%"><a href="#" order_id="{{ orderinfo.order_id }}" status="{{ orderinfo.order_status }}" class="oper_btn">已完成</a></td>
							{% endif %}

						</tr>
					</tbody>
				</table>
			    {% endfor %}


				<div class="pagenation">
                    {% if page.has_previous %}
					    <a href="{% url "user:order" page.previous_page_number %}">上一页</a>
                    {% endif %}

                    {% for index in paginator.page_range %}
                        {% if index == page.number %}
                            <a href="{% url "user:order" index %}" class="active">{{ index }}</a>
                        {% else %}
                            <a href="{% url "user:order" index %}">{{ index }}</a>
                        {% endif %}
                    {% endfor %}

                    {% if page.has_next %}
					    <a href="{% url "user:order" page.next_page_number %}">下一页></a>
                    {% endif %}
				</div>
		</div>
	</div>

    <script type="text/javascript">
    $(function () {
        $('.col04').each(function () {
            count = $(this).prev().text();
            price = $(this).prev().prev().find('.good_price').text();
            $(this).html(parseFloat(count,2)*parseFloat(price,2)+'元');
            }

        )
        }
    )
	console.log(1)
	//绑定点击事件，发起ajax请求
	$(".oper_btn").click(function(){
		status = $(this).attr('status')
		if(status==0){
			//发起支付请求
			order_id = $(this).attr('order_id')
			csrf = $('input[name="csrfmiddlewaretoken"]').val()
			params = {"order_id":order_id, "csrfmiddlewaretoken":csrf}
			$.post('/order/pay', params,function(data){
				if(data.res==3){
					window.open(data.pay_url)
					//ajax 查询，获取交易结果
					$.post('/order/check',params,function(data){
						//
						if(data.res==3){
							alert(data.errmsg)
						}else{
							alert(data.errmsg)
						}
					})
				}
			})
		}else{

		}
	})
    </script>

{% endblock center_body %}
